package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;

public class RateCalActivity extends AppCompatActivity {
    private static final String TAG = "RateCalActivity";
    float rate=0f;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rate_cal);
        String title=getIntent().getStringExtra("title");
        rate=getIntent().getFloatExtra("rate",0f);
        Log.i(TAG, "onCreate: title="+title);
        Log.i(TAG, "onCreate: rate="+rate);
        TextView textView=findViewById(R.id.title2);
        textView.setText(title);
        EditText editText=findViewById(R.id.inp);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                TextView show=findViewById(R.id.show);
                if(s.length()>0){
                    float input=Float.parseFloat(s.toString());
                    show.setText(input+"RMB==>"+(100/rate*input));
                }
                else{
                    show.setText("");
                }
            }
        });
    }
}